package com.usian.listener;

import com.alibaba.fastjson.JSON;
import com.usian.pojo.User;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class MsgListener {

    @KafkaListener(topics = "topic")
    public void xf(ConsumerRecord<?,?> record){
        Optional<? extends ConsumerRecord<?, ?>> optional = Optional.ofNullable(record);
        if (optional.isPresent()){
            String value =(String) record.value();
            User user = JSON.parseObject(value, User.class);
            System.out.println("=======消息内容"+user);
        }
    }
}
